#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
#include<string>

namespace bit
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;
		iterator begin()
		{
			return _str;
		}
		iterator end()
		{
			return _str + _size;
		}
		const_iterator begin() const
		{
			return _str;
		}
		const_iterator end() const
		{
			return _str + _size;
		}
		//string(const char* str="")
		//	:_str(new char[strlen(str)+1])
		//	,_size(strlen(str))
		//	,_capacity(strlen(str))
		//{
		//	strcpy(_str, str);
		//}
		
		// 构造函数
		string(const char* str = "")
			:_size(strlen(str))
		{
			_capacity = _size;
			_str = new char[_capacity + 1];
			strcpy(_str, str);
		}

		// 拷贝构造
		string(const string& s)
		{
			_str = new char[s._capacity + 1];
			strcpy(_str, s._str);
			_capacity = s._capacity;
			_size = s._size;
		}

		const char* c_str()
		{
			return _str;
		}

		size_t size() const
		{
			return _size;
		}

		char& operator[](size_t pos)
		{
			return _str[pos];
		}

		const char& operator[](size_t pos) const
		{
			return _str[pos];
		}
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
	};
    
	void test_string1()
	{
		string s1("hello world");
		cout << s1.c_str() << endl;

		for (size_t i = 0; i < s1.size(); i++)
		{
			s1[i]++;
		}
		cout << endl;
		for (size_t i = 0; i < s1.size(); i++)
		{
			cout << s1[i] << "";
		}
		cout << endl;

		const string s3("xxxxxxx");
		for (size_t i = 0; i < s3.size(); i++)
		{
			// const 修饰对象 无法对其修改
			//s3[i]++;
		}

	}
	void test_string2()
	{
		string s4("hello Iterators");
		for (auto ch : s4)
		{
			cout << ch << "";
		}
		cout << endl;
		string::iterator it4 = s4.begin();
		if (it4 != s4.end())
		{
			cout << it4 << "";
			it4++;
		}
		cout << endl;
		string::const_iterator it5 = s4.begin();
		if (it5 != s4.end())
		{
			cout << it5 << "";
			it5++;
		}
		cout << endl;
	}
    void test_string3()
    {
        
    }
}